<?php
class Default_Model_Status extends Zend_Db_Table{
	protected $_name = 'status';
	protected $_primary = 'id';

	public function listItem($arrParam = null, $options = null){
		$db = Zend_Registry::get('connectDb');
		//$db = Zend_Db::factory($adapter,$config);
		$paginator = $arrParam['paginator'];
		$select = $db->select()
		->from('status AS s',array('id','user','status','number_like','number_comment','img_avatar')) 
		->order("s.id DESC") 
		;
			
		
		if($paginator['itemCountPerPage']>0){
			$page = $paginator['currentPage'];
			$rowCount = $paginator['itemCountPerPage'];
			$select->limitPage($page,$rowCount);
		}
		$result  = $db->fetchAll($select);
		return $result;
	}

	public function saveItem($arrParam = null, $options = null){
		$row =  $this->fetchNew();
		$row->user 	  			= $arrParam['user'];
		$row->status 			= $arrParam["status"];
		$row->img_avatar 		= $arrParam['avatar'];
		$row->number_like 		= 0;
		$row->number_comment 	= 0;
		$row->save();

	}
	public function countItem($arrParam = null, $options = null){
		$db = Zend_Registry::get('connectDb');
		$select = $db->select()
		->from('status AS s',array('COUNT(s.id) AS totalItem'));
		$result = $db->fetchOne($select);
		return $result;
	
	}
	public function deleteStatus($arrParam = null, $options = null){
// 		if($options['task'] == 'admin-delete'){
// 			$where = ' id = ' . $arrParam['id'];
// 			//----- LAY TEN HINH ANH user_avatar
// 			$row = $this->getItem($arrParam,array('task'=>'delete')) ;
// 			$imgName = $row['user_avatar'];
// 			//------ XOA HINH ANH TREN SERVER
// 			if(!empty($imgName)){
// 				$upload_dir = FILES_PATH.'/users' ;
// 				echo $upload_dir.'/orignal/' . $imgName;
// 				$upload = new Zendvn_File_Upload() ;
// 				$upload->removeFile($upload_dir . '/orignal/' . $imgName) ;
// 				$upload->removeFile($upload_dir . '/img100x100/' . $imgName) ;
// 				$upload->removeFile($upload_dir . '/img450x450/' . $imgName) ;
// 			}
// 			$this->delete($where);
// 		}
	
		$where = ' id = ' . $arrParam['id'];
		$this->delete($where);
	}
	

}